@use '../core' as *;

$vertical-padding: $spacing-size-2;
$blog-code-selector: '.post-full pre[class*="language-"]';

pre.code,
#{$blog-code-selector},
pre.code code,
#{$blog-code-selector} code {
    color: black;
    background: none;
    text-align: left;
    white-space: pre;
    word-spacing: normal;
    word-break: normal;
    word-wrap: normal;
    line-height: 1.5;

    -moz-tab-size: 4;
    -o-tab-size: 4;
    tab-size: 4;

    -webkit-hyphens: none;
    -moz-hyphens: none;
    -ms-hyphens: none;
    hyphens: none;

    #{$selector-darkmode} & {
        -webkit-font-smoothing: antialiased;

        color: var(--default-text-color);
    }
}

pre.code,
#{$blog-code-selector} {
    --color-code-background: color-mix(in srgb, var(--color-bg-secondary), var(--color-bg-primary) 70%);

    --comment-color: #5d6376;
    --tag-color: #984f4e;
    --string-color: #c33c3a;
    --punctuation-color: #393a34;
    --keyword-color: #b31ea7;
    --symbol-color: #0e4491;
    --function-color: #393a34;
    --deleted-color: #f54946;
    --selector-color: #0e4491;
    --important-color: #e90;
    --class-name-color: #0e4491;
    --property-color: #2ea248;

    position: relative;
    margin: 0 0 $spacing-size-4;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--color-border-secondary), var(--color-border-primary));
    background-color: var(--color-code-background);
    overflow: visible;
    overflow-y: auto;

    #{$selector-darkmode} & {
        color-scheme: dark;
        --comment-color: #aaabb3;
        --tag-color: #bf9fea;
        --string-color: #bfda7f;
        --punctuation-color: var(--default-text-color);
        --keyword-color: #7ac1d1;
        --symbol-color: #36d8d6;
        --function-color: var(--default-text-color);
        --deleted-color: #9a050f;
        --selector-color: #36d8d6;
        --important-color: #e90;
        --class-name-color: #2b91af;
        --property-color: #7ac1d1;

        border: 1px solid rgb(255, 255, 255, 0.1);
    }
}

pre.code > code,
#{$blog-code-selector} > code {
    position: relative;
    display: inline-block;
    min-width: 100%;
    margin-bottom: -5px;
    padding: $vertical-padding $spacing-size-4;
    font-size: 15px;
    background-color: var(--color-code-background);
    background-size: 3em 3em;
    background-origin: content-box;
    background-attachment: local;
    border: none;
    border-radius: 0;
    overflow-x: auto;
}

pre.code > .language-bash,
#{$blog-code-selector} > .language-bash {
    color: var(--function-color);
}

pre.code.line-numbers.line-numbers code,
#{$blog-code-selector}.line-numbers.line-numbers code {
    padding-left: 3.8em;
}

pre.code.line-numbers.line-numbers .line-numbers-rows,
#{$blog-code-selector}.line-numbers.line-numbers .line-numbers-rows {
    left: 0;
}

pre.code[data-line],
#{$blog-code-selector}[data-line] {
    padding-top: 0;
    padding-bottom: 0;
    padding-left: 0;
}

pre[data-line] code,
#{$blog-code-selector}[data-line] code {
    position: relative;
    padding-left: 4em;
}

pre.code .line-highlight,
#{$blog-code-selector} .line-highlight {
    margin-top: 0;
}

pre.code.line-numbers,
#{$blog-code-selector}.line-numbers {
    position: relative;
    counter-reset: linenumber;
}

pre.code.line-numbers > code,
#{$blog-code-selector}.line-numbers > code {
    position: relative;
    white-space: inherit;
    min-height: calc(100% - 1px);
}

.line-numbers .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 0;
    min-height: 100%;
    padding-top: $vertical-padding;
    font-size: 100%;
    left: -3.8em;
    width: 3em;
    letter-spacing: -1px;

    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
}

.line-numbers-rows > span:before {
    content: counter(linenumber);
    display: block;
    padding-right: 0.8em;
    text-align: right;
}

// Theme colors
// ============
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: var(--comment-color);
    font-style: italic;
}

.token.namespace {
    opacity: 0.7;
}

.token.string {
    color: var(--string-color);
}

.token.punctuation,
.token.operator {
    color: var(--punctuation-color);
}

.token.url,
.token.symbol,
.token.number,
.token.boolean,
.token.variable,
.token.constant,
.token.inserted {
    color: var(--symbol-color);
}

.token.atrule,
.token.keyword,
.token.attr-value,
.language-autohotkey .token.selector,
.language-json .token.boolean,
.language-json .token.number,
code[class*='language-css'] {
    color: var(--keyword-color);
}

.token.function {
    color: var(--function-color);
}

.token.deleted,
.language-autohotkey .token.tag {
    color: var(--deleted-color);
}

.token.important {
    color: var(--important-color);
}

.token.important,
.token.bold {
    font-weight: bold;
}

.token.italic {
    font-style: italic;
}

.token.class-name,
.token.builtin,
.language-json .token.property {
    color: var(--class-name-color);
}

.token.tag {
    color: var(--tag-color);
}

.token.selector {
    color: var(--selector-color);
}

.token.attr-name,
.token.property,
.token.regex,
.token.entity {
    color: var(--property-color);
}

.language-css .token.property {
    color: var(--tag-color);
}

.token.atrule,
.token.attr-name,
.token.attr-value,
.token.boolean,
.token.builtin,
.token.cdata,
.token.class-name,
.token.comment,
.token.constant,
.token.deleted,
.token.doctype,
.token.entity,
.token.inserted,
.token.keyword,
.token.namespace,
.token.number,
.token.operator,
.token.prolog,
.token.property,
.token.regex,
.token.selector,
.token.string,
.token.symbol,
.token.tag,
.token.url,
.token.variable {
    #{$selector-darkmode} & {
        -webkit-font-smoothing: subpixel-antialiased;
    }
}

.line-numbers .line-numbers-rows {
    border-right: 1px solid var(--color-util-brand-100);

    #{$selector-darkmode} & {
        border-right-color: var(--color-border-secondary);
    }
}

.line-numbers-rows > span:before {
    color: var(--color-util-brand-500);
    opacity: 0.33;

    #{$selector-darkmode} & {
        color: var(--color-fg-primary);
    }
}
